<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  

  
  <title>CSS基础知识点--盒子模型 | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="宽度属性宽度：  width：长度值 | 百分比 | auto  最大宽度：  max-width：长度值 | 百分比 | auto  最小宽度：  min-width：长度值 | 百分比 | auto  说明：设置块级元素和替换元素的内容宽度 高度属性高度：  height：长度值 | 百分比 | auto  最大高度：  max-height：长度值 | 百分比 | auto  最小高度：">
<meta name="keywords" content="CSS">
<meta property="og:type" content="article">
<meta property="og:title" content="CSS基础知识点--盒子模型">
<meta property="og:url" content="http://yoursite.com/2019/08/03/CSS基础知识点-盒子模型/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="宽度属性宽度：  width：长度值 | 百分比 | auto  最大宽度：  max-width：长度值 | 百分比 | auto  最小宽度：  min-width：长度值 | 百分比 | auto  说明：设置块级元素和替换元素的内容宽度 高度属性高度：  height：长度值 | 百分比 | auto  最大高度：  max-height：长度值 | 百分比 | auto  最小高度：">
<meta property="og:locale" content="default">
<meta property="og:updated_time" content="2019-09-23T14:46:58.190Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="CSS基础知识点--盒子模型">
<meta name="twitter:description" content="宽度属性宽度：  width：长度值 | 百分比 | auto  最大宽度：  max-width：长度值 | 百分比 | auto  最小宽度：  min-width：长度值 | 百分比 | auto  说明：设置块级元素和替换元素的内容宽度 高度属性高度：  height：长度值 | 百分比 | auto  最大高度：  max-height：长度值 | 百分比 | auto  最小高度：">
  
    <link rel="alternate" href="/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/css/style.css">
</head>
</html>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-CSS基础知识点-盒子模型" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2019/08/03/CSS基础知识点-盒子模型/" class="article-date">
  <time datetime="2019-08-03T08:42:13.000Z" itemprop="datePublished">2019-08-03</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/CSS/">CSS</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      CSS基础知识点--盒子模型
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <hr>
<h2 id="宽度属性"><a href="#宽度属性" class="headerlink" title="宽度属性"></a>宽度属性</h2><p>宽度：</p>
<blockquote>
<p>width：长度值 | 百分比 | auto</p>
</blockquote>
<p>最大宽度：</p>
<blockquote>
<p>max-width：长度值 | 百分比 | auto</p>
</blockquote>
<p>最小宽度：</p>
<blockquote>
<p>min-width：长度值 | 百分比 | auto</p>
</blockquote>
<p>说明：设置块级元素和替换元素的内容宽度</p>
<h2 id="高度属性"><a href="#高度属性" class="headerlink" title="高度属性"></a>高度属性</h2><p>高度：</p>
<blockquote>
<p>height：长度值 | 百分比 | auto</p>
</blockquote>
<p>最大高度：</p>
<blockquote>
<p>max-height：长度值 | 百分比 | auto</p>
</blockquote>
<p>最小高度：</p>
<blockquote>
<p>min-height：长度值 | 百分比 | auto</p>
</blockquote>
<p>说明：设置块级元素和替换元素的内容高度</p>
<h2 id="哪些HTML元素可设置高和宽属性"><a href="#哪些HTML元素可设置高和宽属性" class="headerlink" title="哪些HTML元素可设置高和宽属性"></a>哪些HTML元素可设置高和宽属性</h2><ul>
<li><p>块级元素</p>
</li>
<li><p>替换元素</p>
</li>
</ul>
<p>例如：<code>&lt;input&gt;</code>、<code>&lt;img&gt;</code>、<code>&lt;textarea&gt;</code></p>
<h2 id="边框"><a href="#边框" class="headerlink" title="边框"></a>边框</h2><ul>
<li><p>边框宽度：border-width</p>
</li>
<li><p>边框颜色：border-color</p>
</li>
<li><p>边框样式：border-style</p>
</li>
</ul>
<h3 id="边框宽度"><a href="#边框宽度" class="headerlink" title="边框宽度"></a>边框宽度</h3><p>设置元素边框宽度</p>
<blockquote>
<p>border-width：thin | medium | thick | 长度值</p>
</blockquote>
<h3 id="边框颜色"><a href="#边框颜色" class="headerlink" title="边框颜色"></a>边框颜色</h3><p>设置元素边框颜色</p>
<blockquote>
<p>border-color：颜色 | transparent</p>
</blockquote>
<p>如果不给边框设置颜色，则边框颜色与元素内文本颜色一致</p>
<h3 id="边框样式"><a href="#边框样式" class="headerlink" title="边框样式"></a>边框样式</h3><p>设置元素边框样式</p>
<p>border-style：值</p>
<table>
<thead>
<tr>
<th>值</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>none</td>
<td>定义无边框。默认值</td>
</tr>
<tr>
<td>hidden</td>
<td>与none相同。除非在表格元素中解决边框冲突时</td>
</tr>
<tr>
<td>dotted</td>
<td>定义点状边框。在大多数浏览器中呈现为实线</td>
</tr>
<tr>
<td>dashed</td>
<td>定义虚线。在大多数浏览器中呈现为实线</td>
</tr>
<tr>
<td>solid</td>
<td>定义实线</td>
</tr>
<tr>
<td>double</td>
<td>定义双线</td>
</tr>
<tr>
<td>groove</td>
<td>定义3D凹槽边框</td>
</tr>
<tr>
<td>ridge</td>
<td>定义3D垄状边框</td>
</tr>
<tr>
<td>inset</td>
<td>定义3Dinset边框</td>
</tr>
<tr>
<td>outset</td>
<td>定义3Doutset边框</td>
</tr>
<tr>
<td>inherit</td>
<td>规定应该从父元素继承边框样式</td>
</tr>
</tbody></table>
<h3 id="四个方向的边框"><a href="#四个方向的边框" class="headerlink" title="四个方向的边框"></a>四个方向的边框</h3><p>4个不同方向来表示（上、下、左、右）</p>
<p>表示：</p>
<ul>
<li><p>border-[left | right | top | bottom] - width</p>
</li>
<li><p>border-[left | right | top | bottom] - color</p>
</li>
<li><p>border-[left | right | top | bottom] - style</p>
</li>
</ul>
<h3 id="边框缩写"><a href="#边框缩写" class="headerlink" title="边框缩写"></a>边框缩写</h3><p>所有方向：</p>
<blockquote>
<p>border: [宽度] | [样式] | [颜色]</p>
</blockquote>
<p>不同方向：</p>
<blockquote>
<p>border-top: [宽度] | [样式] | [颜色]</p>
</blockquote>
<blockquote>
<p>border-left: [宽度] | [样式] | [颜色]</p>
</blockquote>
<blockquote>
<p>border-right: [宽度] | [样式] | [颜色]</p>
</blockquote>
<blockquote>
<p>border-bottom: [宽度] | [样式] | [颜色]</p>
</blockquote>
<h2 id="内边距（padding）属性"><a href="#内边距（padding）属性" class="headerlink" title="内边距（padding）属性"></a>内边距（padding）属性</h2><p>设置元素的内容与边框之间的距离（内边距或填充），分4个方向（上、右、左、下）</p>
<ul>
<li><p>padding-top：长度值 | 百分比</p>
</li>
<li><p>padding-right：长度值 | 百分比</p>
</li>
<li><p>padding-bottom：长度值 | 百分比</p>
</li>
<li><p>padding-left：长度值 | 百分比</p>
</li>
</ul>
<p>说明：值不能为负</p>
<h3 id="内边距属性缩写"><a href="#内边距属性缩写" class="headerlink" title="内边距属性缩写"></a>内边距属性缩写</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">padding：值1；//4个方向都为值1</span><br><span class="line"></span><br><span class="line">padding：值1 值2；//上下=值1，左右=值2</span><br><span class="line"></span><br><span class="line">padding：值1 值2 值3；//上=值1，左右=值2，下=值3</span><br><span class="line"></span><br><span class="line">padding：值1 值2 值3 值4；//上=值1，右=值2，下=值3，左=值4</span><br></pre></td></tr></table></figure>

<h2 id="外边距（margin）属性"><a href="#外边距（margin）属性" class="headerlink" title="外边距（margin）属性"></a>外边距（margin）属性</h2><p>设置元素与元素之间的举例（外边距），4个方向（上、右、下、左）</p>
<ul>
<li><p>margin-top：长度值 | 百分比 | auto</p>
</li>
<li><p>margin-right：长度值 | 百分比 | auto</p>
</li>
<li><p>margin-bottom：长度值 | 百分比 | auto</p>
</li>
<li><p>margin-left：长度值 | 百分比 | auto</p>
</li>
</ul>
<p>说明：值可为负</p>
<ul>
<li><p>margin的值为auto，实现水平方向居中显示效果</p>
</li>
<li><p>由浏览器计算外边距</p>
</li>
</ul>
<h3 id="外边距属性缩写"><a href="#外边距属性缩写" class="headerlink" title="外边距属性缩写"></a>外边距属性缩写</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">margin：值1；//4个方向都为值1</span><br><span class="line"></span><br><span class="line">margin：值1 值2；//上下=值1，左右=值2</span><br><span class="line"></span><br><span class="line">margin：值1 值2 值3；//上=值1，左右=值2，下=值3</span><br><span class="line"></span><br><span class="line">margin：值1 值2 值3 值4；//上=值1，右=值2，下=值3，左=值4</span><br></pre></td></tr></table></figure>

<h3 id="外边距要点"><a href="#外边距要点" class="headerlink" title="外边距要点"></a>外边距要点</h3><ul>
<li><p>垂直方向，两个相邻元素都设置外边距，外边距会发生合并</p>
</li>
<li><p>合并后外边距高度 = 两个发生合并外边距的高度中最大值</p>
</li>
</ul>
<h2 id="盒子模型计算"><a href="#盒子模型计算" class="headerlink" title="盒子模型计算"></a>盒子模型计算</h2><p>盒子在页面中所占的宽度 = 左边距 + 左边框 + 左填充 + 内容宽度 + 右边距 + 右边框 + 右填充</p>
<p>高度类似</p>
<p>注意：</p>
<ol>
<li><p>如果没有Doctype文档类型声明，各浏览器按照自己的方式解析。</p>
</li>
<li><p>如果有Doctype文档类型声明，按照标准盒子模型来解析。</p>
</li>
</ol>
<h2 id="display属性"><a href="#display属性" class="headerlink" title="display属性"></a>display属性</h2><p>display有四个属性值，分别是：</p>
<ol>
<li><p>inline：元素将显示为内联元素，元素前后没有换行符</p>
</li>
<li><p>block：元素将显示为块级元素，元素前后会带有换行符</p>
</li>
<li><p>inline-block：元素将显示为行内块元素，元素呈现为inline，具有block相应特性</p>
</li>
<li><p>none：此元素不会被显示</p>
</li>
</ol>
<h3 id="重点"><a href="#重点" class="headerlink" title="重点"></a>重点</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">display: flex;</span><br><span class="line">justify-content: space-between;</span><br><span class="line">// 两个属性结合使用可以让元素在容器中左右均匀分布。最常用于移动端开发</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2019/08/03/CSS基础知识点-盒子模型/" data-id="ck4r400nc000dl0w0uc5kptwc" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/CSS/">CSS</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2019/08/05/CSS基础知识点-背景和样式/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          CSS基础知识点--背景和列表
        
      </div>
    </a>
  
  
    <a href="/2019/08/01/CSS基础知识点-CSS字体样式/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">CSS基础知识点--CSS字体样式(font)</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Ajax/">Ajax</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/CSS/">CSS</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/CSS3/">CSS3</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Dart/">Dart</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Flutter/">Flutter</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Git/">Git</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/HTML/">HTML</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/HTML5/">HTML5</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/JSON/">JSON</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Java/">Java</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/JavaScript/">JavaScript</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/QT/">QT</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/React/">React</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Sass/">Sass</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/TheKnowledgeOf/">TheKnowledgeOf</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/TypeScript/">TypeScript</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/bootstrap/">bootstrap</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/jQuery/">jQuery</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Ajax/">Ajax</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/CSS/">CSS</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/CSS3/">CSS3</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Dart/">Dart</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Flutter/">Flutter</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Git/">Git</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/HTML/">HTML</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/HTML5/">HTML5</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/JSON/">JSON</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Java/">Java</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/JavaScript/">JavaScript</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Javascript/">Javascript</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/QT/">QT</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/React/">React</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Sass/">Sass</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/TheKnowledgeOf/">TheKnowledgeOf</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/TypeScript/">TypeScript</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/bootstrap/">bootstrap</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/jQuery/">jQuery</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/Ajax/" style="font-size: 12.22px;">Ajax</a> <a href="/tags/CSS/" style="font-size: 18.89px;">CSS</a> <a href="/tags/CSS3/" style="font-size: 17.78px;">CSS3</a> <a href="/tags/Dart/" style="font-size: 14.44px;">Dart</a> <a href="/tags/Flutter/" style="font-size: 16.67px;">Flutter</a> <a href="/tags/Git/" style="font-size: 12.22px;">Git</a> <a href="/tags/HTML/" style="font-size: 14.44px;">HTML</a> <a href="/tags/HTML5/" style="font-size: 12.22px;">HTML5</a> <a href="/tags/JSON/" style="font-size: 10px;">JSON</a> <a href="/tags/Java/" style="font-size: 11.11px;">Java</a> <a href="/tags/JavaScript/" style="font-size: 20px;">JavaScript</a> <a href="/tags/Javascript/" style="font-size: 10px;">Javascript</a> <a href="/tags/QT/" style="font-size: 12.22px;">QT</a> <a href="/tags/React/" style="font-size: 15.56px;">React</a> <a href="/tags/Sass/" style="font-size: 11.11px;">Sass</a> <a href="/tags/TheKnowledgeOf/" style="font-size: 11.11px;">TheKnowledgeOf</a> <a href="/tags/TypeScript/" style="font-size: 10px;">TypeScript</a> <a href="/tags/bootstrap/" style="font-size: 11.11px;">bootstrap</a> <a href="/tags/jQuery/" style="font-size: 13.33px;">jQuery</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/12/">December 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/11/">November 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/10/">October 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/09/">September 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/08/">August 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/07/">July 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/06/">June 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/05/">May 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/04/">April 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/03/">March 2019</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2019/12/29/Flutter-MaterialApp常用属性介绍/">Flutter-MaterialApp常用属性介绍</a>
          </li>
        
          <li>
            <a href="/2019/12/29/Flutter-ListView/">Flutter-ListView</a>
          </li>
        
          <li>
            <a href="/2019/12/29/Flutter-AppBar/">Flutter-AppBar</a>
          </li>
        
          <li>
            <a href="/2019/12/29/Flutter-TabBar/">Flutter-TabBar</a>
          </li>
        
          <li>
            <a href="/2019/12/29/Flutter-按钮/">Flutter-按钮</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2019 John Doe<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/script.js"></script>



  </div>
</body>
</html>